home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Express Pd: GALORE
/
Express Pd Galore - The Amiga PD & Shareware CD (1994)(Express Pd)[!][Amiga-CD32-CDTV].iso
/
productivity
/
term
/
termxem.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-16
|
8KB
|
465 lines
/*
** termXEM.c
**
** External emulation support routines
**
** Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
** All Rights Reserved
*/
#include "termGlobal.h"
/* xem_swrite():
*
* Send a few bytes across the serial line.
*/
LONG __saveds __asm
xem_swrite(register __a0 STRPTR Buffer,register __d0 LONG Size)
{
if(WriteRequest)
{
SerWrite(Buffer,Size);
return(0);
}
else
return(-1);
}
/* xem_sbreak():
*
* Send a break signal across the serial line.
*/
LONG __asm __saveds
xem_sbreak(VOID)
{
if(!WriteRequest)
return(-1);
else
{
WriteRequest -> IOSer . io_Command = SDCMD_BREAK;
return((LONG)DoIO(WriteRequest));
}
}
/* xem_sstart():
*
* Restart serial read activity.
*/
VOID __asm __saveds
xem_sstart(VOID)
{
RestartSerial();
}
/* xem_sstop():
*
* Stop serial read activity.
*/
LONG __asm __saveds
xem_sstop(VOID)
{
if(ReadRequest)
{
if(!CheckIO(ReadRequest))
AbortIO(ReadRequest);
WaitIO(ReadRequest);
}
return(0);
}
/* xem_tgets(STRPTR Prompt,STRPTR Buffer,ULONG Size):
*
* Get a string from the user.
*/
LONG __saveds __asm
xem_tgets(register __a0 STRPTR Prompt,register __a1 STRPTR Buffer,register __d0 ULONG Size)
{
return(xpr_gets(Prompt,Buffer));
}
/* xem_tbeep(ULONG Times,ULONG Delay):
*
* Beep the terminal display.
*/
VOID __saveds __asm
xem_tbeep(register __d0 ULONG Times,register __d1 ULONG Delay)
{
WORD i;
for(i = 0 ; i < Times ; i++)
{
/* Handle the visual part. */
if(Config -> TerminalConfig -> BellMode != BELL_AUDIBLE)
{
if(StatusProcess)
Signal(StatusProcess,SIG_BELL);
}
/* Let it beep. */
if(Config -> TerminalConfig -> BellMode == BELL_AUDIBLE || Config -> TerminalConfig -> BellMode == BELL_BOTH)
SoundPlay(SOUND_BELL);
}
}
/* xem_macrodispatch(struct XEmulatorMacroKey *XEM_MacroKey):
*
* Dispatch a macro key call.
*/
LONG __saveds __asm
xem_macrodispatch(register __a0 struct XEmulatorMacroKey *XEM_MacroKey)
{
VOID (*Routine)(VOID);
/* If a routine to call is available (most likely xON or xOFF),
* make a call to it, else process the macro key data.
*/
if(Routine = (VPTR)XEM_MacroKey -> xmk_UserData)
(*Routine)();
else
SerialCommand(MacroKeys -> Keys[XEM_MacroKey -> xmk_Qualifier][XEM_MacroKey -> xmk_Code - 0x50]);
return(0);
}
/* SetEmulatorOptions(BYTE Mode):
*
* Save or load the emulator options.
*/
BYTE
SetEmulatorOptions(BYTE Mode)
{
BYTE Success = FALSE;
/* Is the library available and running? */
if(XEmulatorBase && XEM_IO)
{
/* Are we using the new library code? */
if(XEmulatorBase -> lib_Version >= 4)
{
/* Get the name of the library. */
strcpy(SharedBuffer,FilePart(XEmulatorBase -> lib_Node . ln_Name));
/* Does it have any name? */
if(SharedBuffer[0])
{
UBYTE OtherBuffer[50];
WORD i;
/* Strip the `.library' bit. */
for(i = strlen(SharedBuffer) - 1 ; i >= 0 ; i--)
{
if(SharedBuffer[i] == '.')
{
SharedBuffer[i] = 0;
break;
}
}
/* What are we to do? */
if(Mode == XEM_PREFS_LOAD)
{
/* Restore settings... */
strcpy(OtherBuffer,"ENV:");
if(AddPart(OtherBuffer,SharedBuffer,50))
{
/* If we can't load them,
* reset to defaults.
*/
if(!XEmulatorPreferences(XEM_IO,OtherBuffer,Mode))
{
strcpy(OtherBuffer,"ENV:xem");
if(AddPart(OtherBuffer,SharedBuffer,50))
{
if(XEmulatorPreferences(XEM_IO,OtherBuffer,Mode))
Success = TRUE;
}
}
else
Success = TRUE;
if(!Success)
XEmulatorPreferences(XEM_IO,NULL,XEM_PREFS_RESET);
}
}
else
{
/* Save settings to ENV: */
strcpy(OtherBuffer,"ENV:");
if(AddPart(OtherBuffer,SharedBuffer,50))
{
if(XEmulatorPreferences(XEM_IO,OtherBuffer,Mode))
Success = TRUE;
}
if(Success)
{
Success = FALSE;
/* Save settings to ENVARC: */
strcpy(OtherBuffer,"ENVARC:");
if(AddPart(OtherBuffer,SharedBuffer,50))
{
if(XEmulatorPreferences(XEM_IO,OtherBuffer,Mode))
Success = TRUE;
}
}
}
}
}
}
/* Return result. */
return(Success);
}
/* SetupEmulator(BYTE OpenConsole):
*
* Initialize the XEM_IO structure.
*/
STATIC BYTE
SetupEmulator(VOID)
{
if(!XEM_IO)
{
if(XEM_IO = (struct XEM_IO *)AllocVec(sizeof(struct XEM_IO),MEMF_ANY|MEMF_CLEAR))
{
XEM_IO -> xem_window = Window;
XEM_IO -> xem_font = CurrentFont;
XEM_IO -> xem_signal = &XEM_Signal;
XEM_IO -> xem_screendepth = Window -> WScreen -> RastPort . BitMap -> Depth;
XEM_IO -> xem_sread = xpr_sread;
XEM_IO -> xem_swrite = xem_swrite;
XEM_IO -> xem_sflush = xpr_sflush;
XEM_IO -> xem_sbreak = xem_sbreak;
XEM_IO -> xem_squery = xpr_squery;
XEM_IO -> xem_sstart = xem_sstart;
XEM_IO -> xem_sstop = xem_sstop;
XEM_IO -> xem_tbeep = xem_tbeep;
XEM_IO -> xem_tgets = xem_tgets;
XEM_IO -> xem_toptions = xpr_options;
XEM_IO -> xem_process_macrokeys = xem_macrodispatch;
return(TRUE);
}
}
else
return(FALSE);
return(FALSE);
}
/* CloseEmulator():
*
* Close the emulation library.
*/
VOID
CloseEmulator()
{
if(XEmulatorBase)
{
if(XEM_IO)
{
XEmulatorMacroKeyFilter(XEM_IO,NULL);
XEmulatorCloseConsole(XEM_IO);
XEmulatorCleanup(XEM_IO);
FreeVec(XEM_IO);
XEM_IO = NULL;
}
CloseLibrary(XEmulatorBase);
strcpy(EmulationName,LocaleString(MSG_TERMXEM_NO_EMULATION_TXT));
XEmulatorBase = NULL;
XEM_Signal = NULL;
RasterEnabled = TRUE;
ClearCursor();
Reset();
DrawCursor();
}
}
/* OpenEmulator(STRPTR Name):
*
* Open an emulation library.
*/
BYTE
OpenEmulator(STRPTR Name)
{
CloseEmulator();
XEM_HostData . Source = NULL;
XEM_HostData . Destination = NULL;
XEM_HostData . InESC = FALSE;
XEM_HostData . InCSI = FALSE;
if(XEmulatorBase = OpenLibrary(Name,0))
{
ClearCursor();
Reset();
if(SetupEmulator())
{
SetWrMsk(RPort,DepthMask);
if(XEmulatorSetup(XEM_IO))
{
SetEmulatorOptions(XEM_PREFS_LOAD);
if(XEmulatorOpenConsole(XEM_IO))
{
STRPTR LibName = FilePart(XEmulatorBase -> lib_Node . ln_Name);
strcpy(EmulationName,&LibName[3]);
EmulationName[strlen(EmulationName) - 8] = 0;
SetupXEM_MacroKeys(MacroKeys);
return(TRUE);
}
}
}
DrawCursor();
CloseLibrary(XEmulatorBase);
strcpy(EmulationName,LocaleString(MSG_TERMXEM_NO_EMULATION_TXT));
XEmulatorBase = NULL;
XEM_Signal = NULL;
}
return(FALSE);
}
/* XOff():
*
* Small local routine, complements XOn() in Serial.c
*/
STATIC VOID
XOff(VOID)
{
if(Status == STATUS_HOLDING)
{
UBYTE c = XOF;
SerWrite(&c,1);
Status = STATUS_READY;
}
}
/* SetupXEM_MacroKeys(struct MacroKeys *Keys):
*
* Sets up the internal representation of the macro key
* data to fit the XEM specification.
*/
VOID
SetupXEM_MacroKeys(struct MacroKeys *Keys)
{
/* Are we allowed to do what we want to do? */
if(XEM_MacroKeys && XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
{
WORD i,j,k = 0;
/* Clear the macro list. */
NewList(&XEM_MacroList);
/* Run down the list of qualifiers. */
for(i = XMKQ_NONE ; i <= XMKQ_CONTROL ; i++)
{
/* Run down the function keys. */
for(j = 0 ; j < 10 ; j++)
{
/* If the key has no data attached,
* don't use it in the list.
*/
if(Keys -> Keys[i][j][0])
{
XEM_MacroKeys[k] . xmk_Type = XMKT_RAWKEY;
XEM_MacroKeys[k] . xmk_Qualifier = i;
XEM_MacroKeys[k] . xmk_Code = 0x50 + j;
XEM_MacroKeys[k] . xmk_UserData = NULL;
AddTail(&XEM_MacroList,(struct Node *)&XEM_MacroKeys[k++]);
}
}
}
/* Take care of the rest, add support for the xON key. */
XEM_MacroKeys[k] . xmk_Type = XMKT_COOKED;
XEM_MacroKeys[k] . xmk_Qualifier = NULL;
XEM_MacroKeys[k] . xmk_Code = XON;
XEM_MacroKeys[k] . xmk_UserData = (APTR)DoxON;
AddTail(&XEM_MacroList,(struct Node *)&XEM_MacroKeys[k++]);
/* Take care of the xOFF key. */
XEM_MacroKeys[k] . xmk_Type = XMKT_COOKED;
XEM_MacroKeys[k] . xmk_Qualifier = NULL;
XEM_MacroKeys[k] . xmk_Code = XOF;
XEM_MacroKeys[k] . xmk_UserData = (APTR)XOff;
AddTail(&XEM_MacroList,(struct Node *)&XEM_MacroKeys[k]);
/* Make the emulator notice the new settings. */
XEmulatorMacroKeyFilter(XEM_IO,&XEM_MacroList);
}
}